package com.zengge.zbc.mapper;

import com.zengge.zbc.po.RoomInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
public interface RoomInfoMapper {


    @Select("SELECT * FROM room_info WHERE user_obj_id=#{userObjId} FOR UPDATE")
    @Results(id = "room_info", value = {
            @Result(id = true, column = "object_id", property = "objectId"),
            @Result(column = "room_name", property = "roomName"),
            @Result(column = "user_obj_id", property = "userObjId"),
            @Result(column = "address",property = "address")
    })
    List<RoomInfo> findRoomInfosByUserObjId(@Param("userObjId") long userObjId);


    @Select("SELECT * FROM room_info WHERE object_id=#{objectId}")
    @ResultMap("room_info")
    RoomInfo findRoomInfoByObjectId(@Param("objectId") long objectId);

    @Select("SELECT * FROM room_info WHERE object_id=#{objectId} AND user_obj_id=#{userObjId}")
    @ResultMap("room_info")
    RoomInfo findRoomInfoByObjectIdAndUserObjId(@Param("objectId") long objectId,@Param("userObjId") long userObjId);

    @Insert("INSERT INTO room_info (object_id,room_name,user_obj_id,address) " +
            "VALUES(#{objectId},#{roomName},#{userObjId},#{address})")
    void save(RoomInfo roomInfo);

    @Update("UPDATE room_info SET room_name=#{roomName} WHERE object_id=#{objectId}")
    void update(RoomInfo roomInfo);

    @Delete("DELETE FROM room_info WHERE object_id=#{objectId}")
    void delete(RoomInfo roomInfo);
}
